/*
 * @Author: szx
 * @Date: 2022-05-13 14:24:48
 * @LastEditTime: 2022-05-13 14:47:03
 * @Description:
 * @FilePath: \leetcode\面试题\02\01\01.js
 */
function ListNode(val) {
    this.val = val;
    this.next = null;
}

/**
 * @param {ListNode} head
 * @return {ListNode}
 */
var removeDuplicateNodes = function (head) {
    if (!head || !head.next) return head;
    const set = new Set();
    let cur = head,
        next = head,
        prev = head;
    while (next) {
        if (!set.has(next.val)) {
            set.add(next.val);
            prev = cur;
            cur.val = next.val;
            cur = cur.next;
        }
        next = next.next;
    }
    prev.next = null;
    return head;
};
